package cn.lesaas.esb.component.tuxedo;

import java.net.URI;
import java.util.Map;

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;

@UriParams
public class TuxedoConfiguration implements Cloneable{
	@UriPath
	@Metadata(required = "true")
	protected String host;
	@UriPath
	@Metadata(required = "true")
	protected int port;

	public String getHost() {
		return host;
	}

	/**
	 * The hostname.
	 * <p/>
	 * For the consumer the hostname is localhost or 0.0.0.0 For the producer
	 * the hostname is the remote host to connect to
	 */
	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	/**
	 * The host port number
	 */
	public void setPort(int port) {
		this.port = port;
	}

	public void parseURI(URI uri, Map<String, Object> parameters, TuxedoComponent component) throws Exception {
		setHost(uri.getHost());
		if (uri.getPort() != -1) {
			setPort(uri.getPort());
		}
	}

	public TuxedoConfiguration copy() {
		try {
			TuxedoConfiguration answer = (TuxedoConfiguration) clone();
			return answer;
		} catch (CloneNotSupportedException e) {
			throw new RuntimeCamelException(e);
		}
	}
}
